Crate mprocs_pty
source · [−]Expand description
This crate provides a cross platform API for working with the psuedo terminal (pty) interfaces provided by the system. Unlike other crates in this space, this crate provides a set of traits that allow selecting from different implementations at runtime. This crate is part of wezterm.
use portable_pty::{CommandBuilder, PtySize, native_pty_system, PtySystem};
use anyhow::Error;
// Use the native pty implementation for the system
let pty_system = native_pty_system();
// Create a new pty
let mut pair = pty_system.openpty(PtySize {
rows: 24,
cols: 80,
// Not all systems support pixel_width, pixel_height,
// but it is good practice to set it to something
// that matches the size of the selected font. That
// is more complex than can be shown here in this
// brief example though!
pixel_width: 0,
pixel_height: 0,
})?;
// Spawn a shell into the pty
let cmd = CommandBuilder::new("bash");
let child = pair.slave.spawn_command(cmd)?;
// Read and parse output from the pty with reader
let mut reader = pair.master.try_clone_reader()?;
// Send data to the pty by writing to the master
writeln!(pair.master, "ls -l\r\n")?;
ssh2
If the ssh
feature is enabled, this crate exposes an
ssh::SshSession
type that can wrap an established ssh
session with an implementation of PtySystem
, allowing
you to use the same pty interface with remote ptys.
Re-exports
pub use cmdbuilder::CommandBuilder;
Modules
This module implements a serial port based tty.
This is a bit different from the other implementations in that
we cannot explicitly spawn a process into the serial connection,
so we can only use a CommandBuilder::new_default_prog
with the
openpty
method.
On most (all?) systems, attempting to open multiple instances of
the same serial port will fail.
Working with pseudo-terminals
Structs
Represents the exit status of a child process.
Represents the size of the visible display area in the pty
Traits
Represents a child process spawned into the pty. This handle can be used to wait for or terminate that child process.
Represents the ability to signal a Child to terminate
Represents the master/control end of the pty
The PtySystem
trait allows an application to work with multiple
possible Pty implementations at runtime. This is important on
Windows systems which have a variety of implementations.
Represents the slave side of a pty. Can be used to spawn processes into the pty.